﻿namespace ThinkAway.Plus.Office
{
    class MainClass
    {
        class OfficeConverterOption
        {

            public string[] InputFile { internal get; set; }

            public string[] OutputFile { internal get; set; }
        }

        private readonly IOfficeFormatConvert _officeFormatConvert;

        MainClass()
        {
            _officeFormatConvert = new OfficeFormatConvert();
        }

        static int Main(string[] args)
        {
            var option = new OfficeConverterOption();
            for (int index = 0; index < args.Length; index+=2)
            {
                string command = args[index];
                if(args.Length > 1)
                {
                    string arg = args[index + 1];
                    switch (command)
                    {
                        case "-i":
                        case "/i":
                            option.InputFile = arg.Split(',');
                            break;
                        case "-o":
                        case "/o":
                            option.OutputFile = arg.Split(',');
                            break;
                        case "/?":
                            ShowHelp();
                            return 0;
                    }
                }
            }

            if(option.InputFile != null)
            if(option.OutputFile != null)
            if(option.InputFile.Length > 0)
            if(option.OutputFile.Length > 0)
            if(option.InputFile.Length == option.OutputFile.Length)
            {
                var mainClass = new MainClass();
                return mainClass.ExportPdf(option.InputFile, option.OutputFile);
            }
            //show help .
            ShowHelp();

            return -1;
        }

        private static void ShowHelp()
        {
            System.Console.WriteLine("usage:");

            System.Console.WriteLine("OfficeConverterConsole.exe -i test.doc|aa.doc -o test.pdf|aa.pdf");
        }


        public int ExportPdf(string[] inputFiles,string[] outputFiles)
        {
            return _officeFormatConvert.Convert(inputFiles,outputFiles);
        }
    }
}
